﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataCodeType" @search="getTableDataCodeType">
      <el-row>
        
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="CodeName_FormItem" prop="CodeName" label="条码类型名称">
            <el-input v-model="searchDataCodeType.CodeName" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="CodeDescribe_FormItem" prop="CodeDescribe" label="条码描述">
            <el-input v-model="searchDataCodeType.CodeDescribe" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="CodeRegex_FormItem" prop="CodeRegex" label="条码正则">
            <el-input v-model="searchDataCodeType.CodeRegex" clearable></el-input>
        </el-form-item>
    </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/CodeType/Add'" icon='fa fa-plus' type='primary' :button-text="$t('message._system.common.vm.add')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/CodeType/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message._system.common.vm.batchdelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/CodeType/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message._system.common.vm.import')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/CodeType/CodeTypeExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message._system.common.vm.export')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefCodeType" v-bind="tableDataCodeType">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
          <el-button text type="primary" @click="OnEditrowClick(scope.row)" v-auth="'/api/CodeType/Edit'">{{ $t('message._system.common.vm.edit') }}</el-button>
					<el-button text type="primary" @click="OnDetailsrowClick(scope.row)" v-auth="'/api/CodeType/{id}'">{{ $t('message._system.common.vm.detail') }}</el-button>
					<el-popconfirm :title="$t('message._system.common.vm.deletetip')"  @confirm="onDelete(scope.row)">
						<template #reference>
							<el-button text type="danger" v-auth="'/api/CodeType/BatchDelete'">{{ $t('message._system.common.vm.delete') }}</el-button>
						</template>
					</el-popconfirm>
        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="自定义条码类型管理;true;TyMES.Controllers;CodeType">
import {  ElMessageBox, ElMessage } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { CodeTypeApi } from '/@/api/baseinformation/CodeType';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateCodeType = reactive({
    
});

const searchDataCodeType = ref({
    			CodeName: null,
			CodeDescribe: null,
			CodeRegex: null,

});

// 定义变量内容
const tableRefCodeType = ref();
const tableDataCodeType = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
  
        {title:'条码类型名称',key: 'CodeName',type: 'text',isCheck: true},
        {title:'条码描述',key: 'CodeDescribe',type: 'text',isCheck: true},
        {title:'条码正则',key: 'CodeRegex',type: 'text',isCheck: true},
	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataCodeType = () => {
    tableRefCodeType.value.doSearch(CodeTypeApi().search, searchDataCodeType.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.add'), CreateDialog, null, getTableDataCodeType)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.edit'), EditDialog, row, getTableDataCodeType)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.detail'), DetailsDialog, row, getTableDataCodeType)
};

// 删除
const onDelete = (row: any) => {
    CodeTypeApi().delete([row.ID]).then(() => { getTableDataCodeType()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefCodeType.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      CodeTypeApi().delete(selectedids).then(() => { getTableDataCodeType()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.import'), ImportDialog, null, getTableDataCodeType)
};

const onExport = () => {
	const selected = tableRefCodeType.value.getSelectedRows();
	if (selected.length > 0) {
		CodeTypeApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		CodeTypeApi().export({});
	}
};

// 页面加载时
onMounted(() => {
     
        getTableDataCodeType();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

